package cn.com.oceansoft.osc.ms.service.impl;

import cn.com.oceansoft.osc.ms.config.TencentConfig;
import cn.com.oceansoft.osc.ms.domain.YBYModel;
import cn.com.oceansoft.osc.ms.service.ITencentService;
import cn.com.oceansoft.osc.ms.utils.HttpClientUtil;
import cn.ucox.web.framework.view.ApiResult;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.util.StringUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.URL;
import java.net.URLConnection;
import java.util.HashMap;
import java.util.Map;

@Service
public class TencentServiceImpl implements ITencentService {
    @Resource
    private YBYModel ybyModel;

    @Override
    public ApiResult getImagecompare(Map<String,String> map) {
        if(StringUtil.isEmpty(map.get("image1")))
        {
            return new ApiResult().failure("image1不能为空");
        }
        else
            ybyModel.setImage1(map.get("image1"));
        if(StringUtil.isEmpty(map.get("image2")))
        {
            return new ApiResult().failure("image2不能为空");
        }
        else
            ybyModel.setImage2(map.get("image2"));
        if(StringUtil.isEmpty(map.get("appid")))
        {
            return new ApiResult().failure("appid不能为空");
        }
        else
            ybyModel.setAppid(map.get("appid"));
        if(StringUtil.isEmpty(map.get("token")))
        {
            return new ApiResult().failure("token不能为空");
        }
        else
            ybyModel.setToken(map.get("token"));
        Map<String, String> mapn = new HashMap();
        mapn.put("image1", ybyModel.getImage1());
        mapn.put("image2", ybyModel.getImage2());
        mapn.put("appid", ybyModel.getAppid());
        mapn.put("token", ybyModel.getToken());
        JSONObject jsonObjectR  =HttpClientUtil.doPostString(TencentConfig.YBYUrl.toString(),map);
        return new ApiResult().success(JSONObject.toJSONString(jsonObjectR));
    }
}
